﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

namespace jqGrid.Models
{
    public class CustomSearchViewModel
    {
        #region Properties
        public string ProductID { get; set; }

        public string ProductName { get; set; }

        public int? SupplierID { get; set; }

        public int? CategoryID { get; set; }
        #endregion

        #region Methods
        public string GetFilterExpression()
        {
            StringBuilder filterExpressionBuilder = new StringBuilder();
            if (!String.IsNullOrWhiteSpace(ProductID))
                filterExpressionBuilder.Append(String.Format("ProductID = {0} AND ", ProductID));
            if (!String.IsNullOrWhiteSpace(ProductName))
                filterExpressionBuilder.Append(String.Format("ProductName = \"{0}\" AND ", ProductName));
            if (SupplierID.HasValue)
                filterExpressionBuilder.Append(String.Format("SupplierID = {0} AND ", SupplierID));
            if (CategoryID.HasValue)
                filterExpressionBuilder.Append(String.Format("CategoryID = {0} AND ", CategoryID));
            if (filterExpressionBuilder.Length > 0)
                filterExpressionBuilder.Remove(filterExpressionBuilder.Length - 5, 5);
            return filterExpressionBuilder.ToString();
        }
        #endregion
    }
}